﻿/**********************************************
* 作    者：YuBing
* 创建日期：2009年07月13日
* 描    述：Eval/AppraisalEval.aspx 页面 控制Js,评价块
* 修改日期：xxxx年xx月xx日
***********************************************/

/// 样表类别的change事件
function selStyleTableCls_OnChanged(obj) {
    var selStyleTable = document.getElementById("selStyleTable");
    selStyleTable.options.length = 0;
    selStyleTable.options.add(new Option("请选择样表", "-1"));
    if (obj.value == "-1") {
        return;
    }
    PageMethods.GetStyleTable(parseInt(obj.value),
        function(succ){
            for (var i=0; i<succ.length; i++) {
	            selStyleTable.options.add(new Option(succ[i].StName, succ[i].RID))
	        }
        },
        function(err){
            showMassgeBox(MSG_ERROR_TITLE,MSG_ERROR_MESSAGE);
            return;
        }
    );
}


function reloadAppraisal() {
    window.location.href = "AppraisalEval.aspx";
}

/// 验证Form内容
function checkForm() {
    
    // 验证评价名
    var txtAppName = document.getElementById("txtAppName");
    if (txtAppName.value.trim() == "") {
        showNoticMsg("txtAppName", APPRAISAL_CHECKED_APPNAME_EMPTY);
        return false;
    }
    
//    // 验证评价范围
//    var radios = getObjects("divArea", "radio");
//    var flag = false;
//    for (var i=0; i<radios.length; i++) {
//        if (radios[i].checked) {
//            flag = true;
//            break;
//        }
//    }
//    if (!flag) {
//        showNoticMsgObj(radios[0], APPRAISAL_CHECKED_APPAREA_EMPTY);
//        return false;
//    }
    
    // 验证样表
    var selStyleTable = document.getElementById("selStyleTable");
    var divST = document.getElementById("divST");
    if (divST.style.display != "none") {
        if (selStyleTable.value == "-1") {
            showNoticMsg("selStyleTable", APPRAISAL_CHECKED_STYLETABLE_EMPTY);
            return false;
        }
    }
    /////////验证定性设置规则//
    
    //txtSetYouMin
    //txtSetLiangMin
    //txtSetLiangMax
    //txtSetZhongMin
    //txtSetZhongMax
   // txtSetChaMax
   
   var LiangMax=parseInt(document.getElementById("txtSetLiangMax").value);//良大
   var LiangMin=parseInt(document.getElementById("txtSetLiangMin").value);//良小
   
   var ZhongMax=parseInt(document.getElementById("txtSetZhongMax").value);//中大
   var ZhongMin=parseInt(document.getElementById("txtSetZhongMin").value)//中小
   var ChaMax=parseInt(document.getElementById("txtSetChaMax").value)//差大
   
   //alert(1);
   if(!(LiangMin>ZhongMin &&　LiangMin<LiangMax))
   {
           showMassgeBox("系统提示", "定性评价设置错误", NOTIC,null);
           return false;
   }
   
    if(ZhongMin<=0)
   {
           showMassgeBox("系统提示", "定性评价设置错误", NOTIC,null);
           return false;
   }
    
    
    
    return true;
}

function checkSettingsForm() {    
    // 验证定性设置
    var numcheck = /^\d+(\.\d+)?$/
    var idcheck = /^txtSet\w+$/
    var controlList = document.getElementsByTagName("INPUT");
    for (var i=0; i<controlList.length; i++) {
        if (idcheck.test(controlList[i].id)) {
            if (controlList[i].value.trim() != "" && !numcheck.test(controlList[i].value.trim())) {
                showNoticMsg(controlList[i].id, APPRAISAL_CHECKED_SETTINGS_RIGHTNUM);
                return false;
            }
        }
    }
    return true;
}

/// 结束评价,结束所有批次
function btnFinishAppraisal_OnClick() {
    /// callback:doBtnFinishAppraisal
    showConfirmBox(APPRAISAL_SUBMIT_NEWAPP_TITLE,APPRAISAL_FINISH_FINISHAPP_CONFIRM,doBtnFinishAppraisal)
}

/// 结束评价按钮的单击事件,showConfirmBox的callback
function doBtnFinishAppraisal() {
    PageMethods.FinishAppraisal(
        function(app) {
            window.location.href = "AppraisalEval.aspx";
            return;
        },
        function(err) {
            showMassgeBox(MSG_ERROR_TITLE,MSG_ERROR_MESSAGE);
            return;
        }
    )
}

/// 保存定性设置
function SaveSettings() {
    if (!checkSettingsForm()) return;
    
    var txtSetYouMin = document.getElementById("txtSetYouMin");
    var txtSetYouMax = document.getElementById("txtSetYouMax");
    var youMin;
    if (txtSetYouMin.value.trim() == "") {
        youMin = -1;
    }
    else {
        youMin = parseFloat(txtSetYouMin.value.trim());
    }
    var youMax;
    if (txtSetYouMax.value.trim() == "") {
        youMax = -1;
    }
    else {
        youMax = parseFloat(txtSetYouMax.value.trim());
    }
    var you = {
        "SetName": "优",
        "SetMin": youMin, 
        "SetMax": youMax
    };
    
    
    var txtSetLiangMin = document.getElementById("txtSetLiangMin");
    var txtSetLiangMax = document.getElementById("txtSetLiangMax");
    var liangMin;
    if (txtSetLiangMin.value.trim() == "") {
        liangMin = -1;
    }
    else {
        liangMin = parseFloat(txtSetLiangMin.value.trim());
    }
    var liangMax;
    if (txtSetLiangMax.value.trim() == "") {
        liangMax = -1;
    }
    else {
        liangMax = parseFloat(txtSetLiangMax.value.trim());
    }
    var liang = {
        "SetName": "良",
        "SetMin": liangMin, 
        "SetMax": liangMax
    };
    
    var txtSetZhongMin = document.getElementById("txtSetZhongMin");
    var txtSetZhongMax = document.getElementById("txtSetZhongMax");
    var zhongMin;
    if (txtSetZhongMin.value.trim() == "") {
        zhongMin = -1;
    }
    else {
        zhongMin = parseFloat(txtSetZhongMin.value.trim());
    }
    var zhongMax;
    if (txtSetZhongMax.value.trim() == "") {
        zhongMax = -1;
    }
    else {
        zhongMax = parseFloat(txtSetZhongMax.value.trim());
    }
    var zhong = {
        "SetName": "中",
        "SetMin": zhongMin, 
        "SetMax": zhongMax
    };
    
    var txtSetChaMin = document.getElementById("txtSetChaMin");
    var txtSetChaMax = document.getElementById("txtSetChaMax");
    var chaMin;
    if (txtSetChaMin.value.trim() == "") {
        chaMin = -1;
    }
    else {
        chaMin = parseFloat(txtSetChaMin.value.trim());
    }
    var chaMax;
    if (txtSetChaMax.value.trim() == "") {
        chaMax = -1;
    }
    else {
        chaMax = parseFloat(txtSetChaMax.value.trim());
    }
    var cha = {
        "SetName": "差",
        "SetMin": chaMin, 
        "SetMax": chaMax
    };
    
    var setList = [you, liang, zhong, cha];
    
    PageMethods.SaveSettings(setList, 
        function(succ){
            ClosePopForm('divSettings');
            return;
        },
        function(err){
            showMassgeBox(MSG_ERROR_TITLE,MSG_ERROR_MESSAGE);
            return;
        }
    );
}
